package com.example.stgv;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import com.example.stgv.CalendarView.OnDispatchDateSelectListener;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements
		OnDispatchDateSelectListener {

	private TextView mTextDate;
	private SimpleDateFormat mFormat;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);      
//        mTextDate=(TextView)findViewById(R.id.display_date);
        mFormat = new SimpleDateFormat("d/MM/yyyy",java.util.Locale.getDefault());
        ((CalendarView) findViewById(R.id.calendar)).setOnDispatchDateSelectListener(this);
        Date todays = new Date();
        onDispatchDateSelect(todays);
	}

	@Override
	public void onDispatchDateSelect(Date date) {
//		mTextDate.setText(mFormat.format(date));
		ListView lv = (ListView) findViewById(R.id.lstview_Events);
		ArrayList<String> arrEvent =  CalendarView.getEvents(this,date);
		ArrayAdapter<String> adapter= new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,arrEvent);
        lv.setAdapter(adapter);	
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.my_menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			Intent openSetting = new Intent(MainActivity.this,
					SettingsActivity.class);
			startActivity(openSetting);
		} else if (id == R.id.act_diemdanh) {
			Intent openAttStudent = new Intent(MainActivity.this,
					AttStudent.class);
			startActivity(openAttStudent);;
		} else if (id == R.id.act_diem) {
			Intent openInputScore = new Intent(MainActivity.this,
					InputScore.class);
			startActivity(openInputScore);
		} else if (id == R.id.action_newHS) {
			Intent openStudent = new Intent(MainActivity.this, AddStudent.class);
			startActivity(openStudent);
		} else if (id == R.id.action_newLop) {
			Intent openClass = new Intent(MainActivity.this, AddClass.class);
			startActivity(openClass);
		} else {
		}
		return super.onOptionsItemSelected(item);
	}

	public class BasicAlertDialogFragment extends DialogFragment {
		@Override
		public Dialog onCreateDialog(Bundle savedInstanceState) {
			AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
			// Thiết lập nội dung cần thông báo
			builder.setMessage("Ban co muon thoat chuong trinh?")
					.setPositiveButton("Có",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int id) {
									finish();
								}
							})
					.setNegativeButton("Không",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int id) {
									dialog.cancel();
								}
							});
			return builder.create();
		}
	}
}